<?php

namespace Shen\Rocketmq5\Aspect;

use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;
use Shen\Rocketmq5\Annotation\RocketMq;
use Shen\Rocketmq5\Constant\MsgResult;

class ConsumerAspect extends AbstractAspect
{
    // 要切入的注解，具体切入的还是使用了这些注解的类，仅可切入类注解和类方法注解
    public array $annotations = [
        RocketMq::class,
    ];

    public function process(ProceedingJoinPoint $proceedingJoinPoint)
    {
        $params = $proceedingJoinPoint->getArguments();
        $data = $params[0] ?? [];
        $msgId = $data['msg_id'] ?? '';
        $result = $proceedingJoinPoint->process();
        $res = false;
        if ($result === MsgResult::SUCCESS) {
            $res = true;
        }
        return [
            'msg_id' => $msgId,
            'result' => $res,
        ];
    }
}